part of markdown;

/// 所有这里的正则表达式，都需要用group(1)来表达需要的内容
class Rule {
  /// [Block]判断
  static final empty = RegExp(r'^$');
  static final photo = RegExp(r'!?\[\[(.*?(?:\.png|\.jpg|\.jpeg))\]\]');
  static final head = RegExp(r'[^#]?#{2} (.*)');
  static final code = RegExp(r'`(.*?)`');

  /// [RichBlock]判断
  static final unlist = RegExp(r'- (.*)');

  /// [Span]判断
  static final bold = RegExp(r'\*{2}(.*?)\*{2}');
  static final wiki = RegExp(r'!?\[\[(.*?)(?<!\.jpeg)(?<!\.png)(?<!\.jpg)\]\]');
  static final link = RegExp(r'\[(.*?)\]\((.*?)\)');
}

extension Check on String {
  bool get isEmpty => Rule.empty.hasMatch(this);
  bool get isPhoto => Rule.photo.hasMatch(this);
  bool get isHead => Rule.head.hasMatch(this);
  bool get isCode => Rule.code.hasMatch(this);
  bool get isTop => startsWith("top:");
  bool get isSub => startsWith("副标题");

  bool get isUnlist => Rule.unlist.hasMatch(this);

  bool get isBold => Rule.bold.hasMatch(this);
  bool get isWiki => Rule.wiki.hasMatch(this);
  bool get isLink => Rule.link.hasMatch(this);
}
